log using Vote20-KH_log_v60_ForReleaseR2-FPA, replace

#delimit ;
use Vote20_KH_v6_Release, clear ;
describe ;





** --------------------------- Important!!!----------------------------- 	  ** ;
**   Because this do file will run spatial regression, before running this do ** ;
**   file, you have to check whether your system satisfies the conditions     ** ;
**   below: 																  ** ;
**   1. Your STATA can run spatial regression (STATA 15 or higher).			  ** ;
**   2. You have to put the dataset file and also the TWO GIS files 	      ** ;
**      (VillageKHadj_NLSC_1041007 and VillageKHadj_NLSC_1041007_shp) in the  ** ;
**      same folder. The two GIS files have the geographic information about  ** ;
**      the neighborhoods in Kaohsiung, Taiwan. 							  ** ;

** This is the official version for the publication:						  ** ;
**   The dataset used in this file is the dataset in version 6, where we add  ** ;
**   two variables, "guandi" and "yiguandao," based on the suggestions        ** ;
**   provided by the reviewers in the 2nd round.	 						  ** ;





*gen CityID = round(TownID/100000) ;

** Merge panel data with the Stata-format shapefiles ** ;
merge m:1 ID_Li using VillageKHadj_NLSC_1041007 ;
keep if _merge==3 ;
drop _merge ;





** Generate variables  ** ;
** Dependent variables ** ;
* The difference between the changes in vote-shares of 2018-2014 for DDP and KMT * ;
gen chdppabs18 = ln(DPP_rate_2018/abstention_2018)-ln(DPP_rate_2014/abstention_2014) ;
gen chkmtabs18 = ln(KMT_rate_2018/abstention_2018)-ln(KMT_rate_2014/abstention_2014) ;

gen chcandabs18dk = ( ln(DPP_rate_2018/abstention_2018)-ln(DPP_rate_2014/abstention_2014) )
					- ( ln(KMT_rate_2018/abstention_2018)-ln(KMT_rate_2014/abstention_2014) ) ;

* The difference between the changes in vote-shares of 2020-2016 for DDP and KMT * ;
gen chdppabs20 = ln(DPP_rate_2020/abstention_2020)-ln(DPP_rate_2016/abstention_2016) ;
gen chkmtabs20 = ln(KMT_rate_2020/abstention_2020)-ln(KMT_rate_2016/abstention_2016) ;

gen chcandabs20dk = ( ln(DPP_rate_2020/abstention_2020)-ln(DPP_rate_2016/abstention_2016) )
					- ( ln(KMT_rate_2020/abstention_2020)-ln(KMT_rate_2016/abstention_2016) ) ;



** Key dependent variables ** ;
* Temple_Density ;
gen tempden    = temple / (P_CNT_2018/P_DEN_2018) ;

* Mazu temple_Density ;
gen mazuden    = mazu / (P_CNT_2018/P_DEN_2018) ;
gen lnmazuden      = ln(mazuden+1) ;

* Mazu temple deusity_Urban vs village temples ;
gen urbanmazuden   = urban_mazu / (P_CNT_2018/P_DEN_2018) ;
gen argimazuden    = argi_mazu / (P_CNT_2018/P_DEN_2018) ;
gen lnurbanmazuden = ln(urbanmazuden+1) ;
gen lnargimazuden  = ln(argimazuden+1) ;

* Guandi temple_Density ;
gen guanden = guandi / (P_CNT_2018/P_DEN_2018) ;
gen lnguanden        = ln(guanden+1) ;

gen othertempdenv1 = tempden - mazuden - guanden ;
gen lnothertempdenv1 = ln(othertempdenv1+1) ;

* Yiguandao temple_Density ;
gen yiguanden = yiguandao / (P_CNT_2018/P_DEN_2018) ;
gen lnyiguanden      = ln(yiguanden+1) ;

gen othertempdenv2 = tempden - mazuden - guanden - yiguanden ;
gen lnothertempdenv2 = ln(othertempdenv2+1) ;



** Control variables ** ;
* Church_Density ;
gen churchden = church / (P_CNT_2018/P_DEN_2018) ;
gen lnchurchden = ln(churchden+1) ;


* Average income ;
gen inc_avg_1417 = (inc_2014 + inc_2017)/2 ;

* Housing price (change unit) ;
replace Price_unit_mean_2014_2017 = 10 * Price_unit_mean_2014_2017 ;
replace Price_unit_mean_2014 = 10 * Price_unit_mean_2014 ;
replace Price_unit_mean_2017 = 10 * Price_unit_mean_2017 ;


* Demographic variables ;
gen popch_1418    = P_CNT_2018 - P_CNT_2014 ;
gen popdench_1418 = P_DEN_2018 - P_DEN_2014 ;

gen popden_1418 = (P_DEN_2014 + P_DEN_2018)/2 ;
gen popden_1520 = (P_DEN_2015 + P_DEN_2020)/2 ;

gen old_1418 = ((A65UP_CNT_2018/P_CNT_2018) + (A65UP_CNT_2014/P_CNT_2014))/2 ;
gen old_1520 = ((A65UP_CNT_2020/P_CNT_2020) + (A65UP_CNT_2015/P_CNT_2015))/2 ;

gen old_14 = (A65UP_CNT_2014/P_CNT_2014) ;
gen old_15 = (A65UP_CNT_2015/P_CNT_2015) ;

gen child_1418 = ((A0A5_CNT_2018/P_CNT_2018) + (A0A5_CNT_2014/P_CNT_2014))/2 ;
gen child_1520 = ((A0A5_CNT_2020/P_CNT_2020) + (A0A5_CNT_2015/P_CNT_2015))/2 ;

gen child_14 = (A0A5_CNT_2014/P_CNT_2014) ;
gen child_15 = (A0A5_CNT_2015/P_CNT_2015) ;


* Education ;
gen allcollege_1418 = (((college_2014+jcollege_2014)/P_CNT_2014) +
						   ((college_2018+jcollege_2018)/P_CNT_2018))/2 ;
gen allcollege_1520 = (((college_2015+jcollege_2015)/P_CNT_2015) +
						   ((college_2020+jcollege_2020)/P_CNT_2020))/2 ;

gen allcollege_14 = ((college_2014+jcollege_2014)/P_CNT_2014) ;
gen allcollege_15 = ((college_2015+jcollege_2015)/P_CNT_2015) ;


* City-area ;
gen city = 0 ;
replace city = 1 if TownID<=6401200 ;


* Indigenous towns ;
gen indtn = 0 ;
replace indtn = 1 if TownID==6403600 | TownID==6403700 | TownID==6403800 ;





******************************************************************************** ;

** Descriptive statistics ** ; 
tabstat DPP_rate_2014 DPP_rate_2016 DPP_rate_2018 DPP_rate_2020, stat(n mean sd min max) ;
tabstat KMT_rate_2014 KMT_rate_2016 KMT_rate_2018 KMT_rate_2020, stat(n mean sd min max) ;
tabstat abstention_2014 abstention_2016 abstention_2018 abstention_2020, stat(n mean sd min max) ;

tabstat chdppabs18 chkmtabs18              , stat(n mean sd min max) ;
tabstat chdppabs18 chkmtabs18 if mazuden>0 , stat(n mean sd min max) ;
tabstat chdppabs18 chkmtabs18 if mazuden==0, stat(n mean sd min max) ;

tabstat chdppabs20 chkmtabs20              , stat(n mean sd min max) ;
tabstat chdppabs20 chkmtabs20 if mazuden>0 , stat(n mean sd min max) ;
tabstat chdppabs20 chkmtabs20 if mazuden==0, stat(n mean sd min max) ;

tabstat chcandabs18dk              , stat(n mean sd min max) ;
tabstat chcandabs18dk if mazuden>0 , stat(n mean sd min max) ;
tabstat chcandabs18dk if mazuden==0, stat(n mean sd min max) ;

tabstat chcandabs20dk              , stat(n mean sd min max) ;
tabstat chcandabs20dk if mazuden>0 , stat(n mean sd min max) ;
tabstat chcandabs20dk if mazuden==0, stat(n mean sd min max) ;

tabstat temple mazu urban_mazu argi_mazu, stat(n mean sd min max p25 p50 p75) ;

tabstat tempden mazuden urbanmazuden argimazuden, stat(n mean sd min max p25 p50 p75) ;
tabstat lnmazuden lnurbanmazuden lnargimazuden, stat(n mean sd min max p25 p50 p75) ;
tabstat mazuden urbanmazuden argimazuden if city==1, stat(n mean sd min max p25 p50 p75) ;
tabstat mazuden urbanmazuden argimazuden if city==0, stat(n mean sd min max p25 p50 p75) ;

tabstat guanden   othertempdenv1  , stat(n mean sd min max p25 p50 p75) ;
tabstat lnguanden lnothertempdenv1, stat(n mean sd min max p25 p50 p75) ;

tabstat yiguanden   othertempdenv2  , stat(n mean sd min max p25 p50 p75) ;
tabstat lnyiguanden lnothertempdenv2, stat(n mean sd min max p25 p50 p75) ;


tabstat church               , stat(n mean sd min max p25 p50 p75) ;
tabstat churchden lnchurchden, stat(n mean sd min max p25 p50 p75) ;

tabstat popdench_1418 popden_1418 popden_1520, stat(n mean sd min max) ;
tabstat old_1418    old_1520  , stat(n mean sd min max) ;
tabstat child_1418  child_1520, stat(n mean sd min max) ;

tabstat allcollege_1418 allcollege_1520, stat(n mean sd min max) ;

tabstat inc_avg_1417, stat(n mean sd min max) ;
tabstat Price_unit_mean_2014_2017, stat(n mean sd min max) ;

tabstat hotel_num_2018 hotel_capa_2018 hotel_staff_2018, stat(n mean sd min max) ;

tabstat city indtn, stat(n mean sd) ;





******************************************************************************** ;

** Create spatial weighting W ** ;
spmatrix create idistance  Wd, vtruncate(.5) ;





** Main regression 			** ;
** Spatial regression       ** ;
** Model_distance weighting ** ;

** The four regression commands below are those for the official  ** ;
**   article published in Foreign Policy Analysis.				  ** ;

** Temple types: Mazu, Guandi, and the others		  ;
*    1-1-2018: Mazu, Guandi temples and Other temples ;
spregress chcandabs18dk lnmazuden lnguanden lnothertempdenv1 
			            lnchurchden  
				        popden_1418   
			            child_1418 old_1418  
				        allcollege_1418  
				        inc_avg_1417 Price_unit_mean_2014_2017  
				        hotel_num_2018  
				        city indtn,
						ml   
					    ivarlag(Wd: lnmazuden lnguanden lnothertempdenv1) ;
estat impact lnmazuden lnguanden lnothertempdenv1 ;

*    1-1-2020: Mazu, Guandi temples and Other temples ;
spregress chcandabs20dk lnmazuden lnguanden lnothertempdenv1 
						lnchurchden
					    popden_1520 
			     	    child_1520 old_1520 
				        allcollege_1520
					    inc_avg_1417 Price_unit_mean_2014_2017 
					    hotel_num_2018	
						city indtn,
						ml   
					    ivarlag(Wd: lnmazuden lnguanden lnothertempdenv1) ;
estat impact lnmazuden lnguanden lnothertempdenv1 ;

*    1-2-2018: Other temples, Guandi temples and Mazu temples_Urban vs village temples ;
spregress chcandabs18dk lnurbanmazuden lnargimazuden lnguanden lnothertempdenv1
			            lnchurchden  
				        popden_1418   
			            child_1418 old_1418  
				        allcollege_1418  
				        inc_avg_1417 Price_unit_mean_2014_2017  
				        hotel_num_2018  
				        city indtn,
						ml   
					    ivarlag(Wd: lnurbanmazuden lnargimazuden lnguanden lnothertempdenv1) ;
estat impact lnurbanmazuden lnargimazuden lnguanden lnothertempdenv1 ;
			 
*    1-2-2020: Other temples, Guandi temples and Mazu temples_Urban vs village temples ;
spregress chcandabs20dk lnurbanmazuden lnargimazuden lnguanden lnothertempdenv1
			      lnchurchden 
				  popden_1520 
			      child_1520 old_1520 
				  allcollege_1520 
				  inc_avg_1417 Price_unit_mean_2014_2017 
				  hotel_num_2018					  
				  city indtn, 
				  ml   
				  ivarlag(Wd: lnurbanmazuden lnargimazuden lnguanden lnothertempdenv1) ;
estat impact lnurbanmazuden lnargimazuden lnguanden lnothertempdenv1 ;





** We run the four regression commands below together to do another  ** ;
**   check following the suggestion provided by the reviewer in the  ** ;
**   2nd round.	    												 ** ;

** Temple types: Mazu, Guandi, Yiguandao and the others		     ;
*    2-1-2018: Mazu, Guandi, Yiguandao temples and Other temples ;
spregress chcandabs18dk lnmazuden lnguanden lnyiguanden lnothertempdenv2 
			            lnchurchden  
				        popden_1418   
			            child_1418 old_1418  
				        allcollege_1418  
				        inc_avg_1417 Price_unit_mean_2014_2017  
				        hotel_num_2018  
				        city indtn,
						ml   
					    ivarlag(Wd: lnmazuden lnguanden lnyiguanden lnothertempdenv2) ;
estat impact lnmazuden lnguanden lnyiguanden lnothertempdenv2 ;

*    2-1-2020: Mazu, Guandi, Yiguandao temples and Other temples ;
spregress chcandabs20dk lnmazuden lnguanden lnyiguanden lnothertempdenv2 
						lnchurchden
					    popden_1520 
			     	    child_1520 old_1520 
				        allcollege_1520
					    inc_avg_1417 Price_unit_mean_2014_2017 
					    hotel_num_2018	
						city indtn,
						ml   
					    ivarlag(Wd: lnmazuden lnguanden lnyiguanden lnothertempdenv2) ;
estat impact lnmazuden lnguanden lnyiguanden lnothertempdenv2 ;

*    2-2-2018: Other temples, Guandi, Yiguandao temples and Mazu temples_Urban vs village temples ;
spregress chcandabs18dk lnurbanmazuden lnargimazuden lnguanden lnyiguanden lnothertempdenv2
			            lnchurchden  
				        popden_1418   
			            child_1418 old_1418  
				        allcollege_1418  
				        inc_avg_1417 Price_unit_mean_2014_2017  
				        hotel_num_2018  
				        city indtn,
						ml   
					    ivarlag(Wd: lnurbanmazuden lnargimazuden lnguanden lnyiguanden lnothertempdenv2) ;
estat impact lnurbanmazuden lnargimazuden lnguanden lnyiguanden lnothertempdenv2 ;
			 
*    2-2-2020: Other temples, Guandi, Yiguandao temples and Mazu temples_Urban vs village temples ;
spregress chcandabs20dk lnurbanmazuden lnargimazuden lnguanden lnyiguanden lnothertempdenv2
			      lnchurchden 
				  popden_1520 
			      child_1520 old_1520 
				  allcollege_1520 
				  inc_avg_1417 Price_unit_mean_2014_2017 
				  hotel_num_2018					  
				  city indtn, 
				  ml   
				  ivarlag(Wd: lnurbanmazuden lnargimazuden lnguanden lnyiguanden lnothertempdenv2) ;
estat impact lnurbanmazuden lnargimazuden lnguanden lnyiguanden lnothertempdenv2 ;





log close ;
